/**
 * 表单通用
 * author xty
 */
//通用初始化校验环境
$.validator.setDefaults({
    submitHandler: function() {}});
//注册表单校验事件
function regValidate(forms) {
    if(forms&&forms.length&&forms.length>0){
        for(var i in forms){
            $(forms[i]).validate({
                errorPlacement:function(error,element) {
                    // error.appendTo(element.parents('div .form-group'));
                    var findEle = element.next('.tip');
                    if(!findEle || findEle.length < 1){
                        findEle = element.parents().next('.tip');
                    }
                    error.appendTo(findEle);
                },
                // 聚焦事件
                // onfocusin: function(element) { $(element).valid(); },
                // 失焦事件
                onfocusout: function(element) { $(element).valid(); },
                // 点击事件
                onclick: function(element) { $(element).valid(); },
                // 键盘事件
                onkeyup: function(element) { $(element).valid(); }
            });
        }
    }
}
//获取表单数据
function getFromData(form) {
    var params = $(form).serializeArray();
    var values = {};
    for( x in params ){
        values[params[x].name] = params[x].value;
    }
    return values
}

//  弹框的页面提示取消
function resetFormTip(form) {
    var validateobj = $(form).validate({
        onfocusout: function(element) { $(element).valid();
        }
    });
    validateobj.resetForm();
}

function resetInputCss(form) {
    var path = form + ' div div input';
    $(path).attr('class', 'form-control');
}
//初始化医生信息
function initDocInfoTable(_docInfo){
    $('#_docTable').empty();
    if(!_docInfo||!_docInfo.docId) return;
    var htmStr=" <tbody><tr><td>医生姓名：</td><td colspan='2'>"+_docInfo.name+"</td><td rowspan='3'>头像：</td><td rowspan='3' colspan='2'><img src='"+(_docInfo&&_docInfo.headPhoto?_docInfo.headPhoto:basePath+'/images/main/default.jpg')+"' class='img-rounded win-img'></td></tr>" +
        "<tr><td>科室：</td><td colspan='2'>"+(_docInfo&&_docInfo.sectName?_docInfo.sectName : '')+"</td></tr>" +
        "<tr><td>医生职称：</td><td colspan='2'>"+(_docInfo&&_docInfo.mediLevelName?_docInfo.mediLevelName : '')+"</td></tr>" +
        "<tr><td>执业医院：</td><td  colspan='5'>"+(_docInfo&&_docInfo.hosName?_docInfo.hosName : '')+"</td></tr>" +
        "<tr><td>手机号码：</td><td colspan='2'>"+(_docInfo&&_docInfo.phoneNo?_docInfo.phoneNo : '')+"</td><td>科室电话：</td><td colspan='2'>"+(_docInfo&&_docInfo.sectPhoneNo?_docInfo.sectPhoneNo : '')+"</td></tr>" +
        "<tr><td>电子邮箱：</td><td colspan='3'>"+(_docInfo&&_docInfo.email?_docInfo.email : '')+"</td></tr>" +
        "<tr><td>擅长：</td><td colspan='5'>"+(_docInfo&&_docInfo.goodAt?_docInfo.goodAt : '')+"</td></tr>" +
        "<tr><td>个人简介：</td><td colspan='5'> <textarea   class='form-control' type='text'  style='height: 80px; resize: none;' readonly='readonly'>"+(_docInfo&&_docInfo.resume?_docInfo.resume : '')+"</textarea></td></tr>" +
        "</tbody>";
    $('#_docTable').html(htmStr);
}
//初始化下拉框信息
function initSelectList(obj,data){
    $(obj).empty();
    var htmStr=" <option value=''>--请选择--</option>";
    if(data){
        $.each(data, function(index, val ) {
            console.log( index, val, this );
            htmStr+="<option value='"+val.docId+"' >"+val.name+"</option>";
        } );
    }
    $(obj).html(htmStr);
}
